Skip to content

Conversation

@GrigorenkoPV
Copy link
Contributor

@GrigorenkoPV GrigorenkoPV commented Dec 7, 2025

As suggested in #149174 (comment), this PR adds an ability to omit : () from const item declarations. If the type is omitted, it defaults to (). This is similar to how function declarations treat -> ().

Implementation details:

  • The gate is #![feature(const_items_unit_type_default)] with the same tracking issue as for #![feature(const_block_items)]
  • ast::ConstItem's ty is changed from Box<ast::Ty> into ast::FnRetTy, which is like an Option<Box<Ty>> but with a Span for the None variant.
  • During parsing:
    • static items with unspecified type still give an error, just as before
    • const items with an unspecified type no longer give the previous error, but instead demand that you have the new feature enabled and fallback to : ().
  • During AST->HIR lowering:
    • const items with no type specified in AST get a () in HIR
  • rustfmt support included

TODO:

  • Sadly, it seemes like it undoes the internal compiler error: missing type for const item #69396. Maybe instead of falling back to : (), fallback to : _ (as it was before) when the feature is not enabled?
  • fix the tests that started failing
  • make a separate tracking issue or update Tracking Issue for item-level const blocks #149226
  • is the feature gate name ok?
  • do not reuse FnRetTy or rename it?
  • do the "unspecified means ()" not during AST->HIR, but later on?
  • allow to omit : () for static items too? for consistency. despite static: () being kinda useless.
  • better diagnostic messages?

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. T-lang Relevant to the language team labels Dec 7, 2025
@GrigorenkoPV
Copy link
Contributor Author

CC @joshtriplett as the lang champion

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot removed the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Dec 7, 2025
@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Dec 7, 2025
@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-20-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
+ LL | const C2 = 42;
+    |         ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
+ 
+ error[E0658]: omitting type on const item declaration is experimental
2   --> $DIR/const-no-type.rs:33:8
3    |
4 LL | const C = 42;

-    |        ^ help: provide a type for the constant: `: i32`
+    |        ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
6 
- error: missing type for `const` item
+ error[E0658]: omitting type on const item declaration is experimental
8   --> $DIR/const-no-type.rs:38:8
9    |
10 LL | const D = &&42;

-    |        ^ help: provide a type for the constant: `: &&i32`
+    |        ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
12 
13 error: missing type for `static` item
14   --> $DIR/const-no-type.rs:43:9

22 LL | static mut SM = "abc";
23    |              ^ help: provide a type for the static variable: `: &str`
24 
- error: missing type for `const` item
-   --> $DIR/const-no-type.rs:14:9
+ error[E0308]: mismatched types
+   --> $DIR/const-no-type.rs:33:11
---
+   --> $DIR/const-no-type.rs:38:11
30    |
- help: provide a type for the item
-    |
- LL | const C2: <type> = 42;
-    |         ++++++++
+ LL | const D = &&42;
+    |           ^^^^ expected `()`, found `&&{integer}`
35 
36 error: missing type for `static` item
37   --> $DIR/const-no-type.rs:20:10

55 LL | static mut SM2: <type> = "abc";
56    |               ++++++++
57 
- error: aborting due to 7 previous errors
+ error: aborting due to 9 previous errors
59 
---
+ LL | const C2 = 42;
+    |         ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
+ 
+ error[E0658]: omitting type on const item declaration is experimental
+    |        ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
+ error[E0658]: omitting type on const item declaration is experimental
+    |        ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
+ error[E0308]: mismatched types
+   --> $DIR/const-no-type.rs:33:11
+ LL | const C = 42;
+    |           ^^ expected `()`, found integer
+ 
+ error[E0308]: mismatched types
+   --> $DIR/const-no-type.rs:38:11
+ LL | const D = &&42;
+    |           ^^^^ expected `()`, found `&&{integer}`
+ error: aborting due to 9 previous errors
+ Some errors have detailed explanations: E0308, E0658.
+ For more information about an error, try `rustc --explain E0308`.


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args suggestions/const-no-type.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/suggestions/const-no-type.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/suggestions/const-no-type" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:14:9
   |
LL | const C2 = 42;
   |         ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:33:8
   |
LL | const C = 42;
   |        ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:38:8
   |
LL | const D = &&42;
   |        ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error: missing type for `static` item
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:43:9
   |
LL | static S = Vec::<String>::new();
   |         ^ help: provide a type for the static variable: `: Vec<String>`

error: missing type for `static mut` item
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:48:14
   |
LL | static mut SM = "abc";
   |              ^ help: provide a type for the static variable: `: &str`

error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:33:11
   |
LL | const C = 42;
   |           ^^ expected `()`, found integer

error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:38:11
   |
LL | const D = &&42;
   |           ^^^^ expected `()`, found `&&{integer}`

error: missing type for `static` item
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:20:10
   |
LL | static S2 = "abc";
   |          ^
   |
help: provide a type for the item
   |
LL | static S2: <type> = "abc";
   |          ++++++++

error: missing type for `static mut` item
##[error]  --> /checkout/tests/ui/suggestions/const-no-type.rs:26:15
   |
LL | static mut SM2 = "abc";
   |               ^
   |
help: provide a type for the item
   |
LL | static mut SM2: <type> = "abc";
   |               ++++++++

error: aborting due to 9 previous errors

Some errors have detailed explanations: E0308, E0658.
---
---- [ui] tests/ui/suggestions/unnamable-types.rs stdout ----

error: Error: expected failure status (Some(1)) but received status Some(101).
status: exit status: 101
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/suggestions/unnamable-types.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/suggestions/unnamable-types" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:6:8
   |
LL | const A = 5;
   |        ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:23:8
   |
LL | const D = S { t: { let i = 0; move || -> i32 { i } } };
   |        ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:29:8
   |
LL | const E = foo;
   |        ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:32:8
   |
LL | const F = S { t: foo };
   |        ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:37:8
   |
LL | const G = #[coroutine] || -> i32 { yield 0; return 1; };
   |        ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:10:11
   |
LL | static B: _ = "abc";
   |           ^ not allowed in type signatures
   |
help: replace this with a fully-specified type
   |
LL - static B: _ = "abc";
LL + static B: &str = "abc";
   |

error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:17:10
   |
LL | const C: _ = || 42;
   |          ^ not allowed in type signatures
   |
note: however, the inferred type `{[email protected]:17:14}` cannot be named
  --> /checkout/tests/ui/suggestions/unnamable-types.rs:17:14
   |
LL | const C: _ = || 42;
   |              ^^^^^

error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:6:11
   |
LL | const A = 5;
   |           ^ expected `()`, found integer

error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:23:11
   |
LL | const D = S { t: { let i = 0; move || -> i32 { i } } };
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `S<{[email protected]:23:31}>`
   |
   = note: expected unit type `()`
                 found struct `S<{closure@/checkout/tests/ui/suggestions/unnamable-types.rs:23:31: 23:45}>`

error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:29:11
   |
LL | const E = foo;
   |           ^^^ expected `()`, found fn item
   |
   = note: expected unit type `()`
                found fn item `fn() -> i32 {foo}`

error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/suggestions/unnamable-types.rs:32:11
   |
LL | const F = S { t: foo };
   |           ^^^^^^^^^^^^ expected `()`, found `S<fn() -> i32 {foo}>`
   |
   = note: expected unit type `()`
                 found struct `S<fn() -> i32 {foo}>`


thread 'rustc' (156713) panicked at /checkout/compiler/rustc_hir/src/hir.rs:1353:18:
can't get the span of an arbitrary parsed attribute: Parsed(Coroutine(/checkout/tests/ui/suggestions/unnamable-types.rs:37:11: 37:23 (#0)))
stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_hir_typeck::fn_ctxt::FnCtxt>::precedence::{closure#0}
   3: <rustc_hir::hir::Expr>::precedence
   4: <rustc_hir_typeck::fn_ctxt::FnCtxt>::suggest_deref_ref_or_into
   5: <rustc_hir_typeck::fn_ctxt::FnCtxt>::emit_type_mismatch_suggestions
   6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::emit_coerce_suggestions
   7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::demand_coerce_diag
   8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_coercible_to_type
   9: rustc_hir_typeck::typeck_with_inspect
      [... omitted 3 frames ...]
  10: rustc_mir_build::thir::pattern::check_match::check_match
      [... omitted 3 frames ...]
  11: rustc_middle::query::inner::query_ensure_error_guaranteed::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 1]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, ()>
  12: rustc_mir_build::builder::build_mir
  13: rustc_mir_transform::mir_built
      [... omitted 3 frames ...]
  14: rustc_mir_transform::trivial_const::trivial_const_provider
      [... omitted 3 frames ...]
  15: rustc_const_eval::const_eval::eval_queries::eval_to_const_value_raw_provider
      [... omitted 3 frames ...]
  16: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}
  17: rustc_data_structures::sync::parallel::par_for_each_in::<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners<rustc_hir_analysis::check_crate::{closure#2}>::{closure#0}>
  18: rustc_hir_analysis::check_crate
  19: rustc_interface::passes::analysis
      [... omitted 3 frames ...]
  20: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  21: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
  22: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  23: <alloc::boxed::Box<dyn for<'a> core::ops::function::FnOnce<(&'a rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &'a std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena<'a>>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}), Output = core::option::Option<rustc_interface::queries::Linker>>> as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, alloc::sync::Arc<rustc_data_structures::jobserver::Proxy>, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once
  24: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  25: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
  26: rustc_span::create_session_globals_then::<(), rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

---
note: please make sure that you have updated to the latest nightly

note: rustc 1.94.0-nightly (b087a12cf 2025-12-07) running on aarch64-unknown-linux-gnu

note: compiler flags: -Z threads=1 -Z simulate-remapped-rust-src-base=/rustc/FAKE_PREFIX -Z translate-remapped-path-to-local-path=no -Z ignore-directory-in-diagnostics-source-blocks=/cargo -Z ignore-directory-in-diagnostics-source-blocks=/checkout/vendor -C codegen-units=1 -Z ui-testing -Z deduplicate-diagnostics=no -Z write-long-types-to-disk=no -C strip=debuginfo -C prefer-dynamic -C rpath -C debuginfo=0

query stack during panic:
#0 [typeck] type-checking `G`
#1 [check_match] match-checking `G`
#2 [mir_built] building MIR for `G`
#3 [trivial_const] checking if `G` is a trivial const
#4 [eval_to_const_value_raw] simplifying constant for the type system `G`
#5 [analysis] running analysis passes on crate `unnamable_types`
end of query stack
error: aborting due to 11 previous errors

Some errors have detailed explanations: E0121, E0308, E0658.
For more information about an error, try `rustc --explain E0121`.
---
- error: missing type for `const` item
+ error[E0658]: omitting type on const item declaration is experimental
2   --> $DIR/issue-100164.rs:3:10
3    |
4 LL | const _A: = 123;

-    |          ^ help: provide a type for the constant: `i32`
+    |          ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
6 
- error: missing type for `const` item
+ error[E0658]: omitting type on const item declaration is experimental
8   --> $DIR/issue-100164.rs:7:14
9    |
10 LL |     const _B: = 123;

-    |              ^ help: provide a type for the constant: `i32`
+    |              ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
12 
- error: aborting due to 2 previous errors
+ error[E0308]: mismatched types
+   --> $DIR/issue-100164.rs:3:13
+    |
+ LL | const _A: = 123;
+    |             ^^^ expected `()`, found integer
14 
+ error[E0308]: mismatched types
+   --> $DIR/issue-100164.rs:7:17
+    |
+ LL |     const _B: = 123;
+    |                 ^^^ expected `()`, found integer
+ 
+ error: aborting due to 4 previous errors
+ 
+ Some errors have detailed explanations: E0308, E0658.
---
+ error[E0658]: omitting type on const item declaration is experimental
+    |          ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
+ error[E0658]: omitting type on const item declaration is experimental
+    |              ^
+    |
+    = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
+    = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
+    = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
+    = help: consider specifying the type explicitly
+ error[E0308]: mismatched types
+   --> $DIR/issue-100164.rs:3:13
+    |
+ LL | const _A: = 123;
+    |             ^^^ expected `()`, found integer
+ error[E0308]: mismatched types
+   --> $DIR/issue-100164.rs:7:17
+    |
+ LL |     const _B: = 123;
+    |                 ^^^ expected `()`, found integer
+ 
+ error: aborting due to 4 previous errors
+ 
+ Some errors have detailed explanations: E0308, E0658.
---
diff of fixed:

1 //@ run-rustfix
2 
- const _A: i32 = 123;
+ const _A: = 123;
4 //~^ ERROR: missing type for `const` item
5 
6 fn main() {

-     const _B: i32 = 123;
+     const _B: = 123;
8     //~^ ERROR: missing type for `const` item
9 }
10 


The actual fixed differed from the expected fixed
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args typeck/issue-100164.rs`

error: 2 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/typeck/issue-100164.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/typeck/issue-100164" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/typeck/issue-100164.rs:3:10
   |
LL | const _A: = 123;
   |          ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0658]: omitting type on const item declaration is experimental
##[error]  --> /checkout/tests/ui/typeck/issue-100164.rs:7:14
   |
LL |     const _B: = 123;
   |              ^
   |
   = note: see issue #149226 <https://github.com/rust-lang/rust/issues/149226> for more information
   = help: add `#![feature(const_items_unit_type_default)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
   = help: consider specifying the type explicitly

error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/typeck/issue-100164.rs:3:13
   |
LL | const _A: = 123;
   |             ^^^ expected `()`, found integer

error[E0308]: mismatched types
##[error]  --> /checkout/tests/ui/typeck/issue-100164.rs:7:17
   |
LL |     const _B: = 123;
   |                 ^^^ expected `()`, found integer

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0308, E0658.

@bors
Copy link
Collaborator

bors commented Dec 12, 2025

☔ The latest upstream changes (presumably #149891) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 2, 2026

☔ The latest upstream changes made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants